<template>
  <div>
    <a-input  v-if="!value.filterName" style="width: 100%" @change="onChange" v-model="args"></a-input>
    <a-input v-else style="width: 100%" :placeholder="i18n('filterList.addRoutingPrefix','添加路由前缀')" @change="onChange" v-model="args" ></a-input>
  </div>
</template>

<script>
  export default {
    name: "PrefixPathEdit",
    props: ["value"],
    data() {
      return {
        args: ""
      }
    },
    created() {
      this.init();
    },
    methods: {
      i18n(name,text,key){
          return this.$ti18(name,text,"SysRouting",key);
      },
      init() {
        if (this.value.filterArgs == "") {
          this.args = "";
        } else {
          this.args = (JSON.parse(this.value.filterArgs))._genkey_0;
        }
      },
      onChange(){
        if(!this.value.filterName){
            this.$message.warning(this.i18n('msa.filterNameTips','过滤器名称不能为空'));
          this.args="";
        }else {
          var obj={
            _genkey_0:this.args,
          };
          this.value.filterArgs=JSON.stringify(obj);
        }
      }
    },
    watch: {
      args:function(val,oldval){
        if(val){
          var obj={
            _genkey_0:val
          }
          this.value.filterArgs=JSON.stringify(obj);
        }
      }
    },
  }
</script>

<style scoped>

</style>